<template>
  <el-card
    class="dosage-statistics work-bench-team__card"
    shadow="never"
    body-style="display: flex; flex-direction: column; height: calc(100% - 20px); padding: 10px 15px;"
  >
    <div class="dosage-statistics__header work-bench-team__card__header">
      <span class="work-bench-team__card__title dosage-statistics__title">用量统计 (今日)</span>
    </div>
    <div class="work-bench-team__card__body dosage-statistics__body">
      <div class="dosage-statistics__item" v-for="item in list" :key="item.name">
        <img class="dosage-statistics__item__img" :src="item.img" />
        <div class="dosage-statistics__item__title">{{ item.label }}</div>
        <div>
          <span class="dosage-statistics__item__num">{{ item.value }}</span>
          <span class="dosage-statistics__item__unit">{{ item.unit }}</span>
        </div>
      </div>
    </div>
  </el-card>
</template>

<script>
// ============================== 导入依赖 ============================== //

import dashboardTeamApi from '@admin/views/Workbench/WorkbenchTeam/api'
import img_electric from '../img/electric.png'
import img_water from '../img/water.png'
import img_gas from '../img/gas.png'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'DosageStatistics',

  props: {
    /**
     * 班组ID
     */
    teamId: { type: String, default: '' },
  },

  data() {
    return {
      list: [],
    }
  },

  mounted() {
    this.$nextTick(() => {
      dashboardTeamApi.queryTeamEnergyPie({
        teamId: this.teamId,
        tenantNo: 0,
      }).then((res) => {
        const first = (res.info || [])[0] || {}
        this.list = first.info
        this.list.forEach((item) => {
          item.img = {
            electric: img_electric,
            gas: img_gas,
            water: img_water,
          }[item.name]
        })
      })
    })
  },
}
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
